#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time   : 2021/6/18 23:50
# @Author : cjw
"""装饰器文件"""
from functools import wraps
from loguru import logger


def expect_fail(func):
    """捕获用例已知的异常，打印错误信息，使用例失败"""
    @wraps(func)
    def wrapper(self, num1, num2, error_type):
        try:
            func(self, num1, num2, error_type)
            raise AssertionError(f'预期用例异常未发生：{error_type}')
        except eval(error_type) as e:
            logger.error(e)

    return wrapper
